package cz.proks.easyhelpdesk.gae.core.manager;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import cz.proks.easyhelpdesk.api.ThreadApi;
import cz.proks.easyhelpdesk.api.config.Configuration;
import cz.proks.easyhelpdesk.api.exception.ApiException;
import cz.proks.easyhelpdesk.api.model.Thread;

@Component
public class ThreadManager extends AManager<Thread> implements ThreadApi {
private final Logger log = LoggerFactory.getLogger(getClass());
    
    @Autowired
    @Qualifier(Configuration.Core.DB.THREAD_API)
    private ThreadApi dbApi;
    
    @Override
    public ThreadApi getDbApi() {
        return dbApi;
    }

    @Override
    public void addTicket(Long id, Long ticketId) throws ApiException {
        log.debug("addTicket():: Start with id '{}', ticketId '{}'", id, ticketId);
        
        getDbApi().addTicket(id, ticketId);
        
        log.debug("addTicket():: Exit");
    }

    @Override
    public void removeTicket(Long id, Long ticketId) throws ApiException {
        log.debug("removeTicket():: Start with id '{}', ticketId '{}'", id, ticketId);
        
        getDbApi().removeTicket(id, ticketId);
        
        log.debug("removeTicket():: Exit");
    }              
    
    @Override
    public List<Thread> listForHelpdeskMemberWithPaging(Long helpdeskMemberId, Long from, Long to) throws ApiException {
        log.debug("listForHelpdeskForPaging():: Start with helpdeskMemberId '{}', from '{}', to '{}'", new Object[] {helpdeskMemberId, from, to});
        
        List<Thread> entities = getDbApi().listForHelpdeskMemberWithPaging(helpdeskMemberId, from, to);
        
        log.debug("listForHelpdeskForPaging():: End with {}", (entities == null ? "null list" : "list of " + entities.size() + " elements"));
        return entities;
    }
}
